package com.atguigu.distributed.lock.leecode;

/**
 * 力扣中等82：删除排序链表中的重复元素Ⅱ
 */
public class DeleteDuplicates {
    public ListNode deleteDuplicates (ListNode head) {
        if(head==null){
            return null;
        }
        ListNode res = new ListNode(0);
        res.next = head;
        ListNode cur = res;
        while (cur.next!=null&&cur.next.next!=null){
            if(cur.next.val==cur.next.next.val){
                int temp = cur.next.val;
                while (cur.next!=null&&cur.next.val==temp){
                    cur.next = cur.next.next;
                }
            }else {
                cur = cur.next;
            }
        }
        //返回时去掉表头
        return res.next;
    }
}
